home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Imágenes y mapas de bits / CenterImage / CenterImage.cs next >
Encoding:
Text File  |  2002-05-06  |  1.1 KB  |  38 lines

  1. //------------------------------------------
  2. // CenterImage.cs ⌐ 2001 by Charles Petzold
  3. //------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class CenterImage: PrintableForm
  9. {
  10.      Image image;
  11.  
  12.      public new static void Main()
  13.      {
  14.           Application.Run(new CenterImage());
  15.      }
  16.      public CenterImage()
  17.      {
  18.           Text = "Centrar Imagen";
  19.  
  20.           image = Image.FromFile("..\\..\\..\\Apollo11FullColor.jpg");
  21.      }
  22.      protected override void DoPage(Graphics grfx, Color clr, int cx, int cy)
  23.      {
  24.           grfx.PageUnit = GraphicsUnit.Pixel;
  25.           grfx.PageScale = 1;
  26.  
  27.           RectangleF rectf = grfx.VisibleClipBounds;
  28.  
  29.           float cxImage = grfx.DpiX * image.Width / 
  30.                                              image.HorizontalResolution;
  31.           float cyImage = grfx.DpiY * image.Height / 
  32.                                              image.VerticalResolution;
  33.  
  34.           grfx.DrawImage(image, (rectf.Width  - cxImage) / 2, 
  35.                                 (rectf.Height - cyImage) / 2);
  36.      }
  37. }
  38.